package com.leyou.controller;

import com.leyou.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author: guojy
 * @date: 2020/3/2 15:32
 * @Description:
 * @version: 1.0
 */
@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;

    /**
     * 图片上传
     *
     * @param file 文件
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadImage(@RequestParam(name = "file") MultipartFile file) {
        String url = uploadService.uploadImage(file);
        return ResponseEntity.ok(url);
    }

    /**
     * 上传到阿里云，获取签名
     * @return
     */
    @GetMapping("/signature")
    public ResponseEntity<Map<String, Object>> getsignature() {
        Map<String, Object> map = uploadService.getsignature();
        return ResponseEntity.ok(map);
    }
}
